<template>
  <div class="city-container">
    <!-- 城市标题和产量信息 -->
    <div class="city-header">
      <h1>{{ city }}荔枝产区</h1>
      <p class="production">年产量: {{ production }}吨</p>
      <button class="back-btn" @click="goBack">
        <i class="icon-arrow-left"></i> 返回地图
      </button>
    </div>

    <!-- 主内容区域 -->
    <div class="content-wrapper">
      <!-- 区域列表 -->
      <div class="area-list">
        <h2 class="section-title">产区列表</h2>
        <ul>
          <li 
            v-for="area in regionList" 
            :key="area.id"
            @click="selectArea(area)"
            :class="{ active: selectedArea?.id === area.id }"
          >
            <div class="area-name">{{ area.areaName }}</div>
            <div class="variety-badge">{{ area.varietyName }}</div>
            <i class="icon-arrow-right"></i>
          </li>
        </ul>
      </div>

      <!-- 区域详情 -->
      <div class="area-detail" v-if="selectedArea">
        <div class="detail-header">
          <h2>{{ selectedArea.areaName }}</h2>
          <span class="variety-tag">{{ selectedArea.varietyName }}</span>
          <span v-if="selectedArea.isBrandFarm === 1" class="brand-farm-tag">
            <i class="icon-star"></i> 品牌农户
          </span>
        </div>
        
        <div class="detail-content">
          <div class="detail-image">
            <img :src="selectedArea.imageUrl" :alt="selectedArea.areaName" />
          </div>
          
          <div class="detail-info">
            <h3>产区介绍</h3>
            <div class="introduction-content">
    <p>{{ selectedArea.introduction }}</p>
  </div>
            
            <div class="info-grid">
              <div class="info-item">
                <i class="icon-location"></i>
                <div>
                  <h4>地理位置</h4>
                  <p>经度: {{ selectedArea.longitude }}</p>
                  <p>纬度: {{ selectedArea.latitude }}</p>
                </div>
              </div>
              
              <div class="info-item">
                <i class="icon-variety"></i>
                <div>
                  <h4>主要品种</h4>
                  <p>{{ selectedArea.varietyName }}</p>
                </div>
              </div>
              
             
            </div>
          </div>
        </div>
      </div>

      <!-- 无选择时的提示 -->
      <div class="empty-detail" v-else>
        <i class="icon-info"></i>
        <p>请从左侧列表选择一个产区查看详细信息</p>
      </div>

       <!-- 农户信息 -->
              <div class="info-item farmer-info" 
                   :class="{ 'brand-farmer': selectedArea.isBrandFarm === 1 }">
                <i class="icon-user"></i>
                <div>
                 
                  <p>姓名: {{ selectedArea.name }}</p>
                  <p>电话: {{ selectedArea.phone }}</p>
                  <p v-if="selectedArea.isBrandFarm === 1" class="brand-highlight">
                    <i class="icon-star"></i> 品牌认证农户
                  </p>
                </div>
              </div>
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { useRouter } from 'vue-router'
import { getRegionInfoService } from '@/api/region/region'

const props = defineProps({
  city: String,
  production: Number
})

const router = useRouter()
const regionList = ref([])
const selectedArea = ref(null)

// 获取区域数据
const getRegionList = async () => {
  try {
    const res = await getRegionInfoService(props.city)
    regionList.value = res.data
    // 默认选择第一个区域
    if (regionList.value.length > 0) {
      selectedArea.value = regionList.value[0]
    }
  } catch (error) {
    console.error('获取区域数据失败:', error)
  }
}

// 选择区域
const selectArea = (area) => {
  selectedArea.value = area
}

// 返回地图
const goBack = () => router.go(-1)

// 初始化获取数据
getRegionList()
</script>

<style scoped>
.introduction-content {
  width: 500px;
  max-width: 100%;
  margin-bottom: 20px;
  padding: 12px;
  background: #f8f8f8;
  border-top-left-radius: 6px;
  border-bottom-left-radius: 6px;
 
}

.introduction-content p {
  margin: 0;
  line-height: 1.7;
  color: #444;
}

.introduction-content p {
  margin: 0;
  line-height: 1.7;
  color: #444;
}
.city-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px;
}

.city-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 30px;
  padding-bottom: 15px;
  border-bottom: 1px solid #eee;
}

.city-header h1 {
  font-size: 24px;
  color: #333;
  margin: 0;
}

.production {
  font-size: 16px;
  color: #666;
  margin: 0 20px;
  flex-grow: 1;
}

.back-btn {
  background: #f5f5f5;
  border: none;
  padding: 8px 15px;
  border-radius: 4px;
  cursor: pointer;
  display: flex;
  align-items: center;
  transition: all 0.3s;
}

.back-btn:hover {
  background: #e0e0e0;
}

.back-btn i {
  margin-right: 5px;
}

.content-wrapper {
  display: flex;
  gap: 30px;
}

.area-list {
  width: 300px;
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
  padding: 20px;
}

.section-title {
  font-size: 18px;
  margin-top: 0;
  margin-bottom: 15px;
  color: #333;
}

.area-list ul {
  list-style: none;
  padding: 0;
  margin: 0;
}

.area-list li {
  padding: 12px 15px;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
  transition: all 0.3s;
}

.area-list li:hover {
  background: #f5f5f5;
}

.area-list li.active {
  background: #e3f2fd;
  border-left: 3px solid #2196f3;
}

.area-name {
  font-weight: 500;
  flex-grow: 1;
}

.variety-badge {
  background: #e8f5e9;
  color: #2e7d32;
  font-size: 12px;
  padding: 2px 8px;
  border-radius: 10px;
  margin: 0 10px;
}

.area-list li i {
  color: #999;
}

.area-detail {
  flex-grow: 1;
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
  padding: 20px;
}

.detail-header {
  display: flex;
  align-items: center;
  margin-bottom: 20px;
  padding-bottom: 15px;
  border-bottom: 1px solid #eee;
}

.detail-header h2 {
  margin: 0;
  font-size: 20px;
}

.variety-tag {
  background: #e3f2fd;
  color: #1976d2;
  padding: 4px 10px;
  border-radius: 4px;
  font-size: 14px;
  margin-left: 15px;
}

.brand-farm-tag {
  background: #fff8e1;
  color: #ff8f00;
  padding: 4px 10px;
  border-radius: 4px;
  font-size: 14px;
  margin-left: 10px;
  display: flex;
  align-items: center;
}

.brand-farm-tag i {
  margin-right: 5px;
}

.detail-content {
  display: flex;
  gap: 20px;
}

.detail-image {
  width: 300px;
  height: 200px;
  border-radius: 6px;
  overflow: hidden;
}

.detail-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.detail-info {
  flex-grow: 1;
}

.detail-info h3 {
  margin-top: 0;
  color: #333;
}

.detail-info p {
  color: #555;
  line-height: 1.6;
}

.info-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-top: 20px;
}

.info-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  background: #f9f9f9;
  padding: 15px;
  border-radius: 6px;
}

.info-item i {
  font-size: 20px;
  color: #2196f3;
  margin-top: 3px;
}

.info-item h4 {
  margin: 0 0 5px 0;
  font-size: 16px;
}

.info-item p {
  margin: 0;
  font-size: 14px;
  color: #666;
}

/* 品牌农户特殊样式 */
.brand-farmer {
  background: #fff8e1;
  border: 1px solid #ffd54f;
}

.brand-farmer i {
  color: #ff8f00;
}

.brand-highlight {
  color: #ff8f00 !important;
  font-weight: 500;
  display: flex;
  align-items: center;
  margin-top: 5px;
}

.brand-highlight i {
  margin-right: 5px;
}

.farmer-info {
  grid-column: span 1;
}

.empty-detail {
  flex-grow: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: #999;
  padding: 50px 0;
}

.empty-detail i {
  font-size: 40px;
  margin-bottom: 15px;
}

@media (max-width: 768px) {
  .content-wrapper {
    flex-direction: column;
  }
  
  .area-list {
    width: 100%;
  }
  
  .detail-content {
    flex-direction: column;
  }
  
  .detail-image {
    width: 100%;
  }
  
  .info-grid {
    grid-template-columns: 1fr;
  }
  
  .farmer-info {
    grid-column: span 1;
  }
}
</style>